home *** CD-ROM | disk | FTP | other *** search
- Path: kryten.awinc.com!news
- From: jenna.design@awinc.com (jenna design)
- Newsgroups: comp.lang.c,comp.lang.c++
- Subject: Re: How to the size of a file in C ?
- Date: 10 Feb 1996 03:52:46 GMT
- Organization: A & W Internet Inc.
- Message-ID: <4fh4qe$487@kryten.awinc.com>
- References: <4ffeqa$pjh@brtph500.bnr.ca> <4ffs5g$a71@kryten.awinc.com>
- NNTP-Posting-Host: pme008.awinc.com
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=ISO-8859-1
- X-Newsreader: WinVN 0.99.5
-
-
- >#include <stdio.h>
- >
- >long GetFileSize (char *ptr_fName)
- >{
- > FILE *fp;
- > long f_size;
- >
- > if((fp = fopen(ptr_fName,"r"))==NULL)
- > return 0;
- >
- > fseek(fp, 0L, SEEK_END);
- > f_size = ftell(fp);
- >
- > fclose(fp);
- >
- > return (f_size);
- >}
-
-
-
-
- Thanks to Darrell Grainger for pointing out a pitfall in the
- above code.
- The above function is fairly useless on 16 bit computers
- as if the returned value exceeds the maximum value a long
- variable can hold the variable will overflow.
-
- in 16-bit LONG_MAX is defined as 32767
- in 32-bit LONG_MAX is defined as 2147483647
-
- According to my on-line help, the stat()function may suit
- your task. According to Borland On-line Help stat()
- is not in the ANSI-C standard.
- Portability is listed as DOS|UNIX|WIN16|WIN32|OS2
-
- Grainger, recommends reading the FAQ for this newsgroup.
-
-
-